/*
 * This file is part of TradeHelper library.
 *
 * TradeHelper library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TradeHelper library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TradeHelper library.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.rag.forum.ui;

import com.alee.laf.label.WebLabel;
import com.alee.managers.popup.PopupManager;
import com.alee.managers.popup.WebPopup;

import javax.swing.*;
import java.awt.*;

/**
 * User: mgarin Date: 09.06.12 Time: 19:32
 */

public class LoaderPopup extends WebPopup
{
    private static ImageIcon loaderIcon =
            new ImageIcon ( LoaderPopup.class.getResource ( "icons/loader.gif" ) );

    private static LoaderPopup loaderPopup = null;

    private WebLabel loaderLabel;

    public static void showLoader ( Component component )
    {
        PopupManager.showModalPopup ( component, getInstance (), false, false );
    }

    public static void setLoaderText ( String text )
    {
        getInstance ().setText ( text );
    }

    public static boolean isLoaderVisible ()
    {
        return getInstance ().isShowing ();
    }

    public static LoaderPopup getInstance ()
    {
        if ( loaderPopup == null )
        {
            loaderPopup = new LoaderPopup ();
        }
        return loaderPopup;
    }

    private LoaderPopup ()
    {
        super ();
        setCloseOnFocusLoss ( false );
        setMargin ( 10 );

        loaderLabel = new WebLabel ( loaderIcon );
        loaderLabel.setIconTextGap ( 10 );
        loaderLabel.setHorizontalTextPosition ( WebLabel.CENTER );
        loaderLabel.setVerticalTextPosition ( WebLabel.BOTTOM );
        add ( loaderLabel );
    }

    public void setText ( String text )
    {
        loaderLabel.setText ( text );
        revalidate ();
    }
}